<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@page import="avicit.platform6.api.session.SessionHelper" %>
<%@page import="avicit.platform6.api.sysshirolog.impl.AfterLoginSessionProcess" %>
<%@page import="avicit.platform6.commons.utils.ViewUtil" %>
<%@ page import="java.util.Locale" %>
<%@ taglib prefix="sec" uri="/WEB-INF/tags/shiro.tld" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <base href="<%=ViewUtil.getRequestPath(request)%>">
    <%
        Object lang = session
                .getAttribute(AfterLoginSessionProcess.SESSION_CURRENT_LANGUAGE_CODE);
        String languageCode = "zh_CN";
        if (lang != null) {
            languageCode = lang.toString();
        }
        Locale locale = SessionHelper.getLocaleByUser(request);
    %>
    <link href="static/css/custom/lantop/css/custom.css" type="text/css" rel="stylesheet">
    <jsp:include
            page="/avicit/platform6/component/common/EasyUIJsInclude.jsp"></jsp:include>
    <jsp:include page="/avicit/im/common/ImUIJSCSSInclude.jsp"></jsp:include>
    <jsp:include
            page="/avicit/platform6/modules/system/commonpopup/commonSelectionHead.jsp"></jsp:include>
    <script type="text/javascript"
            src="avicit/im/lantop/basic/archivetemplatemanager/locale/language_<%=languageCode%>.js"></script>
    <script type="text/javascript" src="static/js/platform/index/js/divscroll.js" ></script>
    <title>推荐文件夹设置</title>

    <script type="text/javascript">
        var sysId = "<%=request.getParameter("sysId")%>";

        $(function () {

            $("#dataTable").datagrid({
                animate: false,
                collapsible: false,
                fitColumns: true,
                autoRowHeight: false,
                singleSelect: false,
                pagination: true,
                pageSize: 10,
                pageList: [10, 20, 30],
                striped: true,
                fit: true,
                method: 'post',
                toolbar: '#toolBar',
                url: 'platform/archiveRecommendFolderController/getRecommendFolderDatagrid?sysId=' + sysId,
            })
            $(".datagrid-view2").find(".datagrid-body").perfectScrollbar();
        });


        function saveFolder() {
            var folderName = $("#folderName").val();
            if (folderName != null && folderName != "") {
                $.ajax({
                    url: 'platform/archiveRecommendFolderController/saveFloder',
                    type: 'post',
                    dataType: 'json',
                    data: {
                        "folderName": folderName,
                        "sysId": sysId
                    },
                    success: function (data) {
                        if (data.success == 1) {
                            if (data.flag == 1) {
                            	parent.parent.parent.$.messager.show({
                                    //消息
                                    //保存成功!
                                   /*  title: commonLang.tip.message, */
                                   title:"消息",
                                    msg: "保存成功",
                                    timeout: 500,
                                    showType: 'slide'
                                });
                            } else {
                                $.messager.alert("提示", "已存在名称为<<span style='color:red;font-weight:bold'>" + folderName + "</span>>的文件夹,不能重复添加!", 'warning');
                            }
                        } else if (data.success == 0) {
                        	parent.parent.parent.$.messager.show({
                                //消息
                                //保存失败!
                                /* title: commonLang.tip.message, */
                                title:"消息",
                                msg: "保存失败",
                                timeout: 500,
                                showType: 'slide'
                            });
                        }
                        $('#dd').dialog('close');
                        $("#dataTable").datagrid("load");
                    }
                });
            }else {
                $.messager.alert('提示', "文件夹名称不能为空！", 'warning');
                return;
            }
        }


        function deleteFolder() {
            var rows = $('#dataTable').datagrid('getChecked');
            if (rows != null && rows.length > 0) {
                $.messager.confirm(' 提示', "确定删除选中推荐文件夹吗?", function (r) {
                    if (r) {
                        var folderIds = "";
                        for (var i = 0; i < rows.length; i++) {
                            folderIds += "," + rows[i].id;
                        }
                        $.ajax({
                            url: 'platform/archiveRecommendFolderController/delFloder',
                            type: 'post',
                            dataType: 'json',
                            data: {
                                "folderIds": folderIds.substring(1)
                            },
                            success: function (data) {
                                if (data.success == 1) {
                                	parent.parent.parent.$.messager.show({
                                        //消息
                                        //保存成功!
                                        title: "消息",
                                        msg: "删除成功!",
                                        timeout: 500,
                                        showType: 'slide'
                                    });
                                } else if (data.success == 0) {
                                	parent.parent.parent.$.messager.show({
                                        //消息
                                        //保存失败!
                                        title: "消息",
                                        msg: "删除失败!",
                                        timeout: 500,
                                        showType: 'slide'
                                    });
                                }
                                $('#dd').dialog('close');
                                $("#dataTable").datagrid("load");
                            }
                        });
                    }
                });

            } else {
                $.messager.alert("提示", "请选择需要删除的推荐文件夹!", 'warning');
            }
        }


        // 打开添加计划弹出框
        function opean() {
            $("#folderName").val("");
            $("#dd").dialog('open');
        }

    </script>
</head>
<body class="easyui-layout" fit="true">

<div data-options="region:'center'" border="false">
    <div id="toolBar" style="padding: 10px 22px;">

        <%-- 添加 --%>
        <a id="addFormButton" class="easyui-linkbutton selbtn"
           href="javascript:void(0)" onclick="opean()"> <img
                src="avicit/im/lantop/documents/Filecollection/img/icon_tool08_blue.png"><span
                class="selbtc">新建</span></a>

        <%-- 删除 --%>
        <a id="delfolder" class="easyui-linkbutton selbtn"
           onclick="deleteFolder()" href="javascript:void(0);"> <img
                src="avicit/im/lantop/common/search/image/icon_tool835_blue.png"><span
                class="selbtc">删除</span></a>
    </div>

    <table id="dataTable" class="easyui-datagrid" data-options="
					fitColumns:true,
					scrollbarSize:0,
					fit:true,
					">
        <thead>
        <tr>
            <th data-options="field:'id', halign:'center', align:'center',checkbox: true"
                width="50"></th>
            <%-- 序号 --%>
            <th data-options="field:'sort', align:'center',formatter: function(val,row){return val==null?'':val}, halign:'center',title:'序号'"
                width="150"></th>
            <%-- 文件夹名称 --%>
            <th data-options="field:'folderName',align:'center', halign:'center', formatter: function(val,row){return val==null?'':val},title:'文件夹名称'"
                width="220"></th>
        </tr>
        </thead>
    </table>
</div>


<!-- 添加计划弹出框 -->
<div id="dd" class="easyui-dialog" title="添加文件夹名称"
     style="width: 300px; height: 200px;"
     data-options="iconCls:'icon-save',resizable:true,modal:true,closed:true">
    <div style="text-align: center; padding: 30px 0;">
        文件夹名称
        <input id="folderName" class="easyui-validatebox" data-options="required:false"/>
    </div>
    <div style="text-align: center;">
        <a id="save" class="easyui-linkbutton selbtnc"
           iconCls="icon-im-save" href="javascript:void(0)"
           onclick="saveFolder()">保存</a>
        <a id="back" class="easyui-linkbutton selbtnc" iconCls="icon-im-back"
           href="javascript:void(0)" onclick="$('#dd').dialog('close')">返回</a>
    </div>
</div>
</body>
</html>